// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers.  See the top-level LICENSE file for dates and other
// details.  No copyright assignment is required to contribute to VisIt.

#include <PyExplodeAttributes.h>
#include <ObserverToCallback.h>
#include <stdio.h>
#include <Py2and3Support.h>
#include <PyExplodeAttributes.h>

// ****************************************************************************
// Module: PyExplodeAttributes
//
// Purpose:
//   This class contains attributes for the explode operator.
//
// Note:       Autogenerated by xml2python. Do not modify by hand!
//
// Programmer: xml2python
// Creation:   omitted
//
// ****************************************************************************

//
// This struct contains the Python type information and a ExplodeAttributes.
//
struct ExplodeAttributesObject
{
    PyObject_HEAD
    ExplodeAttributes *data;
    bool        owns;
    PyObject   *parent;
};

//
// Internal prototypes
//
static PyObject *NewExplodeAttributes(int);
std::string
PyExplodeAttributes_ToString(const ExplodeAttributes *atts, const char *prefix, const bool forLogging)
{
    std::string str;
    char tmpStr[1000];

    const char *explosionType_names = "Point, Plane, Cylinder";
    switch (atts->GetExplosionType())
    {
      case ExplodeAttributes::Point:
          snprintf(tmpStr, 1000, "%sexplosionType = %sPoint  # %s\n", prefix, prefix, explosionType_names);
          str += tmpStr;
          break;
      case ExplodeAttributes::Plane:
          snprintf(tmpStr, 1000, "%sexplosionType = %sPlane  # %s\n", prefix, prefix, explosionType_names);
          str += tmpStr;
          break;
      case ExplodeAttributes::Cylinder:
          snprintf(tmpStr, 1000, "%sexplosionType = %sCylinder  # %s\n", prefix, prefix, explosionType_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    {   const double *explosionPoint = atts->GetExplosionPoint();
        snprintf(tmpStr, 1000, "%sexplosionPoint = (", prefix);
        str += tmpStr;
        for(int i = 0; i < 3; ++i)
        {
            snprintf(tmpStr, 1000, "%g", explosionPoint[i]);
            str += tmpStr;
            if(i < 2)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const double *planePoint = atts->GetPlanePoint();
        snprintf(tmpStr, 1000, "%splanePoint = (", prefix);
        str += tmpStr;
        for(int i = 0; i < 3; ++i)
        {
            snprintf(tmpStr, 1000, "%g", planePoint[i]);
            str += tmpStr;
            if(i < 2)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const double *planeNorm = atts->GetPlaneNorm();
        snprintf(tmpStr, 1000, "%splaneNorm = (", prefix);
        str += tmpStr;
        for(int i = 0; i < 3; ++i)
        {
            snprintf(tmpStr, 1000, "%g", planeNorm[i]);
            str += tmpStr;
            if(i < 2)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const double *cylinderPoint1 = atts->GetCylinderPoint1();
        snprintf(tmpStr, 1000, "%scylinderPoint1 = (", prefix);
        str += tmpStr;
        for(int i = 0; i < 3; ++i)
        {
            snprintf(tmpStr, 1000, "%g", cylinderPoint1[i]);
            str += tmpStr;
            if(i < 2)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const double *cylinderPoint2 = atts->GetCylinderPoint2();
        snprintf(tmpStr, 1000, "%scylinderPoint2 = (", prefix);
        str += tmpStr;
        for(int i = 0; i < 3; ++i)
        {
            snprintf(tmpStr, 1000, "%g", cylinderPoint2[i]);
            str += tmpStr;
            if(i < 2)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    snprintf(tmpStr, 1000, "%smaterialExplosionFactor = %g\n", prefix, atts->GetMaterialExplosionFactor());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%smaterial = \"%s\"\n", prefix, atts->GetMaterial().c_str());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%scylinderRadius = %g\n", prefix, atts->GetCylinderRadius());
    str += tmpStr;
    if(atts->GetExplodeMaterialCells())
        snprintf(tmpStr, 1000, "%sexplodeMaterialCells = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%sexplodeMaterialCells = 0\n", prefix);
    str += tmpStr;
    snprintf(tmpStr, 1000, "%scellExplosionFactor = %g\n", prefix, atts->GetCellExplosionFactor());
    str += tmpStr;
    const char *explosionPattern_names = "Impact, Scatter";
    switch (atts->GetExplosionPattern())
    {
      case ExplodeAttributes::Impact:
          snprintf(tmpStr, 1000, "%sexplosionPattern = %sImpact  # %s\n", prefix, prefix, explosionPattern_names);
          str += tmpStr;
          break;
      case ExplodeAttributes::Scatter:
          snprintf(tmpStr, 1000, "%sexplosionPattern = %sScatter  # %s\n", prefix, prefix, explosionPattern_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    if(atts->GetExplodeAllCells())
        snprintf(tmpStr, 1000, "%sexplodeAllCells = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%sexplodeAllCells = 0\n", prefix);
    str += tmpStr;
    {   const stringVector &boundaryNames = atts->GetBoundaryNames();
        snprintf(tmpStr, 1000, "%sboundaryNames = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < boundaryNames.size(); ++i)
        {
            snprintf(tmpStr, 1000, "\"%s\"", boundaryNames[i].c_str());
            str += tmpStr;
            if(i < boundaryNames.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    { // new scope
        int index = 0;
        // Create string representation of explosions from atts.
        for(AttributeGroupVector::const_iterator pos = atts->GetExplosions().begin(); pos != atts->GetExplosions().end(); ++pos, ++index)
        {
            const ExplodeAttributes *current = (const ExplodeAttributes *)(*pos);
            snprintf(tmpStr, 1000, "GetExplosions(%d).", index);
            std::string objPrefix(prefix + std::string(tmpStr));
            str += PyExplodeAttributes_ToString(current, objPrefix.c_str(), forLogging);
        }
        if(index == 0)
            str += "#explosions does not contain any ExplodeAttributes objects.\n";
    }
    return str;
}

static PyObject *
ExplodeAttributes_Notify(PyObject *self, PyObject *args)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)self;
    obj->data->Notify();
    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ExplodeAttributes_SetExplosionType(PyObject *self, PyObject *args)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 3)
    {
        std::stringstream ss;
        ss << "An invalid explosionType value was given." << std::endl;
        ss << "Valid values are in the range [0,2]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " Point";
        ss << ", Plane";
        ss << ", Cylinder";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the explosionType in the object.
    obj->data->SetExplosionType(ExplodeAttributes::ExplodeType(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ExplodeAttributes_GetExplosionType(PyObject *self, PyObject *args)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetExplosionType()));
    return retval;
}

/*static*/ PyObject *
ExplodeAttributes_SetExplosionPoint(PyObject *self, PyObject *args)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)self;

    PyObject *packaged_args = 0;
    double *vals = obj->data->GetExplosionPoint();

    if (!PySequence_Check(args) || PyUnicode_Check(args))
        return PyErr_Format(PyExc_TypeError, "Expecting a sequence of numeric args");

    // break open args seq. if we think it matches this API's needs
    if (PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PySequence_Check(packaged_args) && !PyUnicode_Check(packaged_args) &&
            PySequence_Size(packaged_args) == 3)
            args = packaged_args;
    }

    if (PySequence_Size(args) != 3)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "Expecting 3 numeric args");
    }

    for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
    {
        PyObject *item = PySequence_GetItem(args, i);

        if (!PyNumber_Check(item))
        {
            Py_DECREF(item);
            Py_XDECREF(packaged_args);
            return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
        }

        double val = PyFloat_AsDouble(item);
        double cval = double(val);

        if (val == -1 && PyErr_Occurred())
        {
            Py_XDECREF(packaged_args);
            Py_DECREF(item);
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ double", (int) i);
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
        {
            Py_XDECREF(packaged_args);
            Py_DECREF(item);
            return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ double", (int) i);
        }
        Py_DECREF(item);

        vals[i] = cval;
    }

    Py_XDECREF(packaged_args);

    // Mark the explosionPoint in the object as modified.
    obj->data->SelectExplosionPoint();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ExplodeAttributes_GetExplosionPoint(PyObject *self, PyObject *args)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the explosionPoint.
    PyObject *retval = PyTuple_New(3);
    const double *explosionPoint = obj->data->GetExplosionPoint();
    for(int i = 0; i < 3; ++i)
        PyTuple_SET_ITEM(retval, i, PyFloat_FromDouble(explosionPoint[i]));
    return retval;
}

/*static*/ PyObject *
ExplodeAttributes_SetPlanePoint(PyObject *self, PyObject *args)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)self;

    PyObject *packaged_args = 0;
    double *vals = obj->data->GetPlanePoint();

    if (!PySequence_Check(args) || PyUnicode_Check(args))
        return PyErr_Format(PyExc_TypeError, "Expecting a sequence of numeric args");

    // break open args seq. if we think it matches this API's needs
    if (PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PySequence_Check(packaged_args) && !PyUnicode_Check(packaged_args) &&
            PySequence_Size(packaged_args) == 3)
            args = packaged_args;
    }

    if (PySequence_Size(args) != 3)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "Expecting 3 numeric args");
    }

    for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
    {
        PyObject *item = PySequence_GetItem(args, i);

        if (!PyNumber_Check(item))
        {
            Py_DECREF(item);
            Py_XDECREF(packaged_args);
            return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
        }

        double val = PyFloat_AsDouble(item);
        double cval = double(val);

        if (val == -1 && PyErr_Occurred())
        {
            Py_XDECREF(packaged_args);
            Py_DECREF(item);
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ double", (int) i);
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
        {
            Py_XDECREF(packaged_args);
            Py_DECREF(item);
            return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ double", (int) i);
        }
        Py_DECREF(item);

        vals[i] = cval;
    }

    Py_XDECREF(packaged_args);

    // Mark the planePoint in the object as modified.
    obj->data->SelectPlanePoint();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ExplodeAttributes_GetPlanePoint(PyObject *self, PyObject *args)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the planePoint.
    PyObject *retval = PyTuple_New(3);
    const double *planePoint = obj->data->GetPlanePoint();
    for(int i = 0; i < 3; ++i)
        PyTuple_SET_ITEM(retval, i, PyFloat_FromDouble(planePoint[i]));
    return retval;
}

/*static*/ PyObject *
ExplodeAttributes_SetPlaneNorm(PyObject *self, PyObject *args)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)self;

    PyObject *packaged_args = 0;
    double *vals = obj->data->GetPlaneNorm();

    if (!PySequence_Check(args) || PyUnicode_Check(args))
        return PyErr_Format(PyExc_TypeError, "Expecting a sequence of numeric args");

    // break open args seq. if we think it matches this API's needs
    if (PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PySequence_Check(packaged_args) && !PyUnicode_Check(packaged_args) &&
            PySequence_Size(packaged_args) == 3)
            args = packaged_args;
    }

    if (PySequence_Size(args) != 3)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "Expecting 3 numeric args");
    }

    for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
    {
        PyObject *item = PySequence_GetItem(args, i);

        if (!PyNumber_Check(item))
        {
            Py_DECREF(item);
            Py_XDECREF(packaged_args);
            return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
        }

        double val = PyFloat_AsDouble(item);
        double cval = double(val);

        if (val == -1 && PyErr_Occurred())
        {
            Py_XDECREF(packaged_args);
            Py_DECREF(item);
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ double", (int) i);
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
        {
            Py_XDECREF(packaged_args);
            Py_DECREF(item);
            return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ double", (int) i);
        }
        Py_DECREF(item);

        vals[i] = cval;
    }

    Py_XDECREF(packaged_args);

    // Mark the planeNorm in the object as modified.
    obj->data->SelectPlaneNorm();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ExplodeAttributes_GetPlaneNorm(PyObject *self, PyObject *args)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the planeNorm.
    PyObject *retval = PyTuple_New(3);
    const double *planeNorm = obj->data->GetPlaneNorm();
    for(int i = 0; i < 3; ++i)
        PyTuple_SET_ITEM(retval, i, PyFloat_FromDouble(planeNorm[i]));
    return retval;
}

/*static*/ PyObject *
ExplodeAttributes_SetCylinderPoint1(PyObject *self, PyObject *args)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)self;

    PyObject *packaged_args = 0;
    double *vals = obj->data->GetCylinderPoint1();

    if (!PySequence_Check(args) || PyUnicode_Check(args))
        return PyErr_Format(PyExc_TypeError, "Expecting a sequence of numeric args");

    // break open args seq. if we think it matches this API's needs
    if (PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PySequence_Check(packaged_args) && !PyUnicode_Check(packaged_args) &&
            PySequence_Size(packaged_args) == 3)
            args = packaged_args;
    }

    if (PySequence_Size(args) != 3)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "Expecting 3 numeric args");
    }

    for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
    {
        PyObject *item = PySequence_GetItem(args, i);

        if (!PyNumber_Check(item))
        {
            Py_DECREF(item);
            Py_XDECREF(packaged_args);
            return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
        }

        double val = PyFloat_AsDouble(item);
        double cval = double(val);

        if (val == -1 && PyErr_Occurred())
        {
            Py_XDECREF(packaged_args);
            Py_DECREF(item);
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ double", (int) i);
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
        {
            Py_XDECREF(packaged_args);
            Py_DECREF(item);
            return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ double", (int) i);
        }
        Py_DECREF(item);

        vals[i] = cval;
    }

    Py_XDECREF(packaged_args);

    // Mark the cylinderPoint1 in the object as modified.
    obj->data->SelectCylinderPoint1();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ExplodeAttributes_GetCylinderPoint1(PyObject *self, PyObject *args)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the cylinderPoint1.
    PyObject *retval = PyTuple_New(3);
    const double *cylinderPoint1 = obj->data->GetCylinderPoint1();
    for(int i = 0; i < 3; ++i)
        PyTuple_SET_ITEM(retval, i, PyFloat_FromDouble(cylinderPoint1[i]));
    return retval;
}

/*static*/ PyObject *
ExplodeAttributes_SetCylinderPoint2(PyObject *self, PyObject *args)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)self;

    PyObject *packaged_args = 0;
    double *vals = obj->data->GetCylinderPoint2();

    if (!PySequence_Check(args) || PyUnicode_Check(args))
        return PyErr_Format(PyExc_TypeError, "Expecting a sequence of numeric args");

    // break open args seq. if we think it matches this API's needs
    if (PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PySequence_Check(packaged_args) && !PyUnicode_Check(packaged_args) &&
            PySequence_Size(packaged_args) == 3)
            args = packaged_args;
    }

    if (PySequence_Size(args) != 3)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "Expecting 3 numeric args");
    }

    for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
    {
        PyObject *item = PySequence_GetItem(args, i);

        if (!PyNumber_Check(item))
        {
            Py_DECREF(item);
            Py_XDECREF(packaged_args);
            return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
        }

        double val = PyFloat_AsDouble(item);
        double cval = double(val);

        if (val == -1 && PyErr_Occurred())
        {
            Py_XDECREF(packaged_args);
            Py_DECREF(item);
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ double", (int) i);
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
        {
            Py_XDECREF(packaged_args);
            Py_DECREF(item);
            return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ double", (int) i);
        }
        Py_DECREF(item);

        vals[i] = cval;
    }

    Py_XDECREF(packaged_args);

    // Mark the cylinderPoint2 in the object as modified.
    obj->data->SelectCylinderPoint2();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ExplodeAttributes_GetCylinderPoint2(PyObject *self, PyObject *args)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the cylinderPoint2.
    PyObject *retval = PyTuple_New(3);
    const double *cylinderPoint2 = obj->data->GetCylinderPoint2();
    for(int i = 0; i < 3; ++i)
        PyTuple_SET_ITEM(retval, i, PyFloat_FromDouble(cylinderPoint2[i]));
    return retval;
}

/*static*/ PyObject *
ExplodeAttributes_SetMaterialExplosionFactor(PyObject *self, PyObject *args)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    double val = PyFloat_AsDouble(args);
    double cval = double(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ double");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ double");
    }

    Py_XDECREF(packaged_args);

    // Set the materialExplosionFactor in the object.
    obj->data->SetMaterialExplosionFactor(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ExplodeAttributes_GetMaterialExplosionFactor(PyObject *self, PyObject *args)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(obj->data->GetMaterialExplosionFactor());
    return retval;
}

/*static*/ PyObject *
ExplodeAttributes_SetMaterial(PyObject *self, PyObject *args)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the material in the object.
    obj->data->SetMaterial(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ExplodeAttributes_GetMaterial(PyObject *self, PyObject *args)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetMaterial().c_str());
    return retval;
}

/*static*/ PyObject *
ExplodeAttributes_SetCylinderRadius(PyObject *self, PyObject *args)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    double val = PyFloat_AsDouble(args);
    double cval = double(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ double");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ double");
    }

    Py_XDECREF(packaged_args);

    // Set the cylinderRadius in the object.
    obj->data->SetCylinderRadius(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ExplodeAttributes_GetCylinderRadius(PyObject *self, PyObject *args)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(obj->data->GetCylinderRadius());
    return retval;
}

/*static*/ PyObject *
ExplodeAttributes_SetExplodeMaterialCells(PyObject *self, PyObject *args)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the explodeMaterialCells in the object.
    obj->data->SetExplodeMaterialCells(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ExplodeAttributes_GetExplodeMaterialCells(PyObject *self, PyObject *args)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetExplodeMaterialCells()?1L:0L);
    return retval;
}

/*static*/ PyObject *
ExplodeAttributes_SetCellExplosionFactor(PyObject *self, PyObject *args)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    double val = PyFloat_AsDouble(args);
    double cval = double(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ double");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ double");
    }

    Py_XDECREF(packaged_args);

    // Set the cellExplosionFactor in the object.
    obj->data->SetCellExplosionFactor(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ExplodeAttributes_GetCellExplosionFactor(PyObject *self, PyObject *args)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(obj->data->GetCellExplosionFactor());
    return retval;
}

/*static*/ PyObject *
ExplodeAttributes_SetExplosionPattern(PyObject *self, PyObject *args)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 2)
    {
        std::stringstream ss;
        ss << "An invalid explosionPattern value was given." << std::endl;
        ss << "Valid values are in the range [0,1]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " Impact";
        ss << ", Scatter";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the explosionPattern in the object.
    obj->data->SetExplosionPattern(ExplodeAttributes::ExplosionPattern(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ExplodeAttributes_GetExplosionPattern(PyObject *self, PyObject *args)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetExplosionPattern()));
    return retval;
}

/*static*/ PyObject *
ExplodeAttributes_SetExplodeAllCells(PyObject *self, PyObject *args)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the explodeAllCells in the object.
    obj->data->SetExplodeAllCells(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ExplodeAttributes_GetExplodeAllCells(PyObject *self, PyObject *args)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetExplodeAllCells()?1L:0L);
    return retval;
}

/*static*/ PyObject *
ExplodeAttributes_SetBoundaryNames(PyObject *self, PyObject *args)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)self;

    stringVector vec;

    if (PyUnicode_Check(args))
    {
        char const *val = PyUnicode_AsUTF8(args);
        std::string cval = std::string(val);
        if (val == 0 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ string");
        }
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyUnicode_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a unicode string", (int) i);
            }

            char const *val = PyUnicode_AsUTF8(item);
            std::string cval = std::string(val);

            if (val == 0 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ string", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more string(s)");

    obj->data->GetBoundaryNames() = vec;
    // Mark the boundaryNames in the object as modified.
    obj->data->SelectBoundaryNames();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ExplodeAttributes_GetBoundaryNames(PyObject *self, PyObject *args)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the boundaryNames.
    const stringVector &boundaryNames = obj->data->GetBoundaryNames();
    PyObject *retval = PyTuple_New(boundaryNames.size());
    for(size_t i = 0; i < boundaryNames.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyString_FromString(boundaryNames[i].c_str()));
    return retval;
}

/*static*/ PyObject *
ExplodeAttributes_GetExplosions(PyObject *self, PyObject *args)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)self;
    int index = -1;
    if (args == NULL)
        return PyErr_Format(PyExc_NameError, "Use .GetExplosions(int index) to get a single entry");
    if (!PyArg_ParseTuple(args, "i", &index))
        return PyErr_Format(PyExc_TypeError, "arg must be a single integer index");
    if (index < 0 || (size_t)index >= obj->data->GetExplosions().size())
        return PyErr_Format(PyExc_ValueError, "index out of range");

    // Since the new object will point to data owned by the this object,
    // we need to increment the reference count.
    Py_INCREF(self);

    PyObject *retval = PyExplodeAttributes_Wrap(&obj->data->GetExplosions(index));
    // Set the object's parent so the reference to the parent can be decref'd
    // when the child goes out of scope.
    PyExplodeAttributes_SetParent(retval, self);

    return retval;
}

PyObject *
ExplodeAttributes_GetNumExplosions(PyObject *self, PyObject *args)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)self;
    return PyInt_FromLong((long)obj->data->GetExplosions().size());
}

PyObject *
ExplodeAttributes_AddExplosions(PyObject *self, PyObject *args)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)self;
    PyObject *element = NULL;
    if(!PyArg_ParseTuple(args, "O", &element))
        return NULL;
    if(!PyExplodeAttributes_Check(element))
        return PyErr_Format(PyExc_TypeError, "expected attr object of type ExplodeAttributes");
    ExplodeAttributes *newData = PyExplodeAttributes_FromPyObject(element);
    obj->data->AddExplosions(*newData);
    obj->data->SelectExplosions();
    Py_INCREF(Py_None);
    return Py_None;
}

static PyObject *
ExplodeAttributes_Remove_One_Explosions(PyObject *self, int index)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)self;
    // Remove in the AttributeGroupVector instead of calling RemoveExplosions() because we don't want to delete the object; just remove it.
    AttributeGroupVector &atts = obj->data->GetExplosions();
    AttributeGroupVector::iterator pos = atts.begin();
    // Iterate through the vector "index" times.
    for(int i = 0; i < index; ++i)
        ++pos;

    // If pos is still a valid iterator, remove that element.
    if(pos != atts.end())
    {
        // NOTE: Leak the object since other Python objects may reference it. Ideally,
        // we would put the object into some type of pool to be cleaned up later but
        // this will do for now.
        //
        // delete *pos;
        atts.erase(pos);
    }

    obj->data->SelectExplosions();
    Py_INCREF(Py_None);
    return Py_None;
}

PyObject *
ExplodeAttributes_RemoveExplosions(PyObject *self, PyObject *args)
{
    int index = -1;
    if(!PyArg_ParseTuple(args, "i", &index))
        return PyErr_Format(PyExc_TypeError, "Expecting integer index");
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)self;
    if(index < 0 || index >= obj->data->GetNumExplosions())
        return PyErr_Format(PyExc_IndexError, "Index out of range");

    return ExplodeAttributes_Remove_One_Explosions(self, index);
}

PyObject *
ExplodeAttributes_ClearExplosions(PyObject *self, PyObject *args)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)self;
    int n = obj->data->GetNumExplosions();
    for(int i = 0; i < n; ++i)
    {
        ExplodeAttributes_Remove_One_Explosions(self, 0);
        Py_DECREF(Py_None);
    }
    Py_INCREF(Py_None);
    return Py_None;
}



PyMethodDef PyExplodeAttributes_methods[EXPLODEATTRIBUTES_NMETH] = {
    {"Notify", ExplodeAttributes_Notify, METH_VARARGS},
    {"SetExplosionType", ExplodeAttributes_SetExplosionType, METH_VARARGS},
    {"GetExplosionType", ExplodeAttributes_GetExplosionType, METH_VARARGS},
    {"SetExplosionPoint", ExplodeAttributes_SetExplosionPoint, METH_VARARGS},
    {"GetExplosionPoint", ExplodeAttributes_GetExplosionPoint, METH_VARARGS},
    {"SetPlanePoint", ExplodeAttributes_SetPlanePoint, METH_VARARGS},
    {"GetPlanePoint", ExplodeAttributes_GetPlanePoint, METH_VARARGS},
    {"SetPlaneNorm", ExplodeAttributes_SetPlaneNorm, METH_VARARGS},
    {"GetPlaneNorm", ExplodeAttributes_GetPlaneNorm, METH_VARARGS},
    {"SetCylinderPoint1", ExplodeAttributes_SetCylinderPoint1, METH_VARARGS},
    {"GetCylinderPoint1", ExplodeAttributes_GetCylinderPoint1, METH_VARARGS},
    {"SetCylinderPoint2", ExplodeAttributes_SetCylinderPoint2, METH_VARARGS},
    {"GetCylinderPoint2", ExplodeAttributes_GetCylinderPoint2, METH_VARARGS},
    {"SetMaterialExplosionFactor", ExplodeAttributes_SetMaterialExplosionFactor, METH_VARARGS},
    {"GetMaterialExplosionFactor", ExplodeAttributes_GetMaterialExplosionFactor, METH_VARARGS},
    {"SetMaterial", ExplodeAttributes_SetMaterial, METH_VARARGS},
    {"GetMaterial", ExplodeAttributes_GetMaterial, METH_VARARGS},
    {"SetCylinderRadius", ExplodeAttributes_SetCylinderRadius, METH_VARARGS},
    {"GetCylinderRadius", ExplodeAttributes_GetCylinderRadius, METH_VARARGS},
    {"SetExplodeMaterialCells", ExplodeAttributes_SetExplodeMaterialCells, METH_VARARGS},
    {"GetExplodeMaterialCells", ExplodeAttributes_GetExplodeMaterialCells, METH_VARARGS},
    {"SetCellExplosionFactor", ExplodeAttributes_SetCellExplosionFactor, METH_VARARGS},
    {"GetCellExplosionFactor", ExplodeAttributes_GetCellExplosionFactor, METH_VARARGS},
    {"SetExplosionPattern", ExplodeAttributes_SetExplosionPattern, METH_VARARGS},
    {"GetExplosionPattern", ExplodeAttributes_GetExplosionPattern, METH_VARARGS},
    {"SetExplodeAllCells", ExplodeAttributes_SetExplodeAllCells, METH_VARARGS},
    {"GetExplodeAllCells", ExplodeAttributes_GetExplodeAllCells, METH_VARARGS},
    {"SetBoundaryNames", ExplodeAttributes_SetBoundaryNames, METH_VARARGS},
    {"GetBoundaryNames", ExplodeAttributes_GetBoundaryNames, METH_VARARGS},
    {"GetExplosions", ExplodeAttributes_GetExplosions, METH_VARARGS},
    {"GetNumExplosions", ExplodeAttributes_GetNumExplosions, METH_VARARGS},
    {"AddExplosions", ExplodeAttributes_AddExplosions, METH_VARARGS},
    {"RemoveExplosions", ExplodeAttributes_RemoveExplosions, METH_VARARGS},
    {"ClearExplosions", ExplodeAttributes_ClearExplosions, METH_VARARGS},
    {NULL, NULL}
};

//
// Type functions
//

static void
ExplodeAttributes_dealloc(PyObject *v)
{
   ExplodeAttributesObject *obj = (ExplodeAttributesObject *)v;
   if(obj->parent != 0)
       Py_DECREF(obj->parent);
   if(obj->owns)
       delete obj->data;
}

static PyObject *ExplodeAttributes_richcompare(PyObject *self, PyObject *other, int op);
PyObject *
PyExplodeAttributes_getattr(PyObject *self, char *name)
{
    if(strcmp(name, "explosionType") == 0)
        return ExplodeAttributes_GetExplosionType(self, NULL);
    if(strcmp(name, "Point") == 0)
        return PyInt_FromLong(long(ExplodeAttributes::Point));
    if(strcmp(name, "Plane") == 0)
        return PyInt_FromLong(long(ExplodeAttributes::Plane));
    if(strcmp(name, "Cylinder") == 0)
        return PyInt_FromLong(long(ExplodeAttributes::Cylinder));

    if(strcmp(name, "explosionPoint") == 0)
        return ExplodeAttributes_GetExplosionPoint(self, NULL);
    if(strcmp(name, "planePoint") == 0)
        return ExplodeAttributes_GetPlanePoint(self, NULL);
    if(strcmp(name, "planeNorm") == 0)
        return ExplodeAttributes_GetPlaneNorm(self, NULL);
    if(strcmp(name, "cylinderPoint1") == 0)
        return ExplodeAttributes_GetCylinderPoint1(self, NULL);
    if(strcmp(name, "cylinderPoint2") == 0)
        return ExplodeAttributes_GetCylinderPoint2(self, NULL);
    if(strcmp(name, "materialExplosionFactor") == 0)
        return ExplodeAttributes_GetMaterialExplosionFactor(self, NULL);
    if(strcmp(name, "material") == 0)
        return ExplodeAttributes_GetMaterial(self, NULL);
    if(strcmp(name, "cylinderRadius") == 0)
        return ExplodeAttributes_GetCylinderRadius(self, NULL);
    if(strcmp(name, "explodeMaterialCells") == 0)
        return ExplodeAttributes_GetExplodeMaterialCells(self, NULL);
    if(strcmp(name, "cellExplosionFactor") == 0)
        return ExplodeAttributes_GetCellExplosionFactor(self, NULL);
    if(strcmp(name, "explosionPattern") == 0)
        return ExplodeAttributes_GetExplosionPattern(self, NULL);
    if(strcmp(name, "Impact") == 0)
        return PyInt_FromLong(long(ExplodeAttributes::Impact));
    if(strcmp(name, "Scatter") == 0)
        return PyInt_FromLong(long(ExplodeAttributes::Scatter));

    if(strcmp(name, "explodeAllCells") == 0)
        return ExplodeAttributes_GetExplodeAllCells(self, NULL);
    if(strcmp(name, "boundaryNames") == 0)
        return ExplodeAttributes_GetBoundaryNames(self, NULL);
    if(strcmp(name, "explosions") == 0)
        return ExplodeAttributes_GetExplosions(self, NULL);


    // Add a __dict__ answer so that dir() works
    if (!strcmp(name, "__dict__"))
    {
        PyObject *result = PyDict_New();
        for (int i = 0; PyExplodeAttributes_methods[i].ml_meth; i++)
            PyDict_SetItem(result,
                PyString_FromString(PyExplodeAttributes_methods[i].ml_name),
                PyString_FromString(PyExplodeAttributes_methods[i].ml_name));
        return result;
    }

    return Py_FindMethod(PyExplodeAttributes_methods, self, name);
}

int
PyExplodeAttributes_setattr(PyObject *self, char *name, PyObject *args)
{
    PyObject NULL_PY_OBJ;
    PyObject *obj = &NULL_PY_OBJ;

    if(strcmp(name, "explosionType") == 0)
        obj = ExplodeAttributes_SetExplosionType(self, args);
    else if(strcmp(name, "explosionPoint") == 0)
        obj = ExplodeAttributes_SetExplosionPoint(self, args);
    else if(strcmp(name, "planePoint") == 0)
        obj = ExplodeAttributes_SetPlanePoint(self, args);
    else if(strcmp(name, "planeNorm") == 0)
        obj = ExplodeAttributes_SetPlaneNorm(self, args);
    else if(strcmp(name, "cylinderPoint1") == 0)
        obj = ExplodeAttributes_SetCylinderPoint1(self, args);
    else if(strcmp(name, "cylinderPoint2") == 0)
        obj = ExplodeAttributes_SetCylinderPoint2(self, args);
    else if(strcmp(name, "materialExplosionFactor") == 0)
        obj = ExplodeAttributes_SetMaterialExplosionFactor(self, args);
    else if(strcmp(name, "material") == 0)
        obj = ExplodeAttributes_SetMaterial(self, args);
    else if(strcmp(name, "cylinderRadius") == 0)
        obj = ExplodeAttributes_SetCylinderRadius(self, args);
    else if(strcmp(name, "explodeMaterialCells") == 0)
        obj = ExplodeAttributes_SetExplodeMaterialCells(self, args);
    else if(strcmp(name, "cellExplosionFactor") == 0)
        obj = ExplodeAttributes_SetCellExplosionFactor(self, args);
    else if(strcmp(name, "explosionPattern") == 0)
        obj = ExplodeAttributes_SetExplosionPattern(self, args);
    else if(strcmp(name, "explodeAllCells") == 0)
        obj = ExplodeAttributes_SetExplodeAllCells(self, args);
    else if(strcmp(name, "boundaryNames") == 0)
        obj = ExplodeAttributes_SetBoundaryNames(self, args);

    if (obj != NULL && obj != &NULL_PY_OBJ)
        Py_DECREF(obj);

    if (obj == &NULL_PY_OBJ)
    {
        obj = NULL;
        PyErr_Format(PyExc_NameError, "name '%s' is not defined", name);
    }
    else if (obj == NULL && !PyErr_Occurred())
        PyErr_Format(PyExc_RuntimeError, "unknown problem with '%s'", name);

    return (obj != NULL) ? 0 : -1;
}

static int
ExplodeAttributes_print(PyObject *v, FILE *fp, int flags)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)v;
    fprintf(fp, "%s", PyExplodeAttributes_ToString(obj->data, "",false).c_str());
    return 0;
}

PyObject *
ExplodeAttributes_str(PyObject *v)
{
    ExplodeAttributesObject *obj = (ExplodeAttributesObject *)v;
    return PyString_FromString(PyExplodeAttributes_ToString(obj->data,"", false).c_str());
}

//
// The doc string for the class.
//
#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 5)
static const char *ExplodeAttributes_Purpose = "This class contains attributes for the explode operator.";
#else
static char *ExplodeAttributes_Purpose = "This class contains attributes for the explode operator.";
#endif

//
// Python Type Struct Def Macro from Py2and3Support.h
//
//         VISIT_PY_TYPE_OBJ( VPY_TYPE,
//                            VPY_NAME,
//                            VPY_OBJECT,
//                            VPY_DEALLOC,
//                            VPY_PRINT,
//                            VPY_GETATTR,
//                            VPY_SETATTR,
//                            VPY_STR,
//                            VPY_PURPOSE,
//                            VPY_RICHCOMP,
//                            VPY_AS_NUMBER)

//
// The type description structure
//

VISIT_PY_TYPE_OBJ(ExplodeAttributesType,         \
                  "ExplodeAttributes",           \
                  ExplodeAttributesObject,       \
                  ExplodeAttributes_dealloc,     \
                  ExplodeAttributes_print,       \
                  PyExplodeAttributes_getattr,   \
                  PyExplodeAttributes_setattr,   \
                  ExplodeAttributes_str,         \
                  ExplodeAttributes_Purpose,     \
                  ExplodeAttributes_richcompare, \
                  0); /* as_number*/

//
// Helper function for comparing.
//
static PyObject *
ExplodeAttributes_richcompare(PyObject *self, PyObject *other, int op)
{
    // only compare against the same type 
    if ( Py_TYPE(self) != &ExplodeAttributesType
         || Py_TYPE(other) != &ExplodeAttributesType)
    {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }

    PyObject *res = NULL;
    ExplodeAttributes *a = ((ExplodeAttributesObject *)self)->data;
    ExplodeAttributes *b = ((ExplodeAttributesObject *)other)->data;

    switch (op)
    {
       case Py_EQ:
           res = (*a == *b) ? Py_True : Py_False;
           break;
       case Py_NE:
           res = (*a != *b) ? Py_True : Py_False;
           break;
       default:
           res = Py_NotImplemented;
           break;
    }

    Py_INCREF(res);
    return res;
}

//
// Helper functions for object allocation.
//

static ExplodeAttributes *defaultAtts = 0;
static ExplodeAttributes *currentAtts = 0;

static PyObject *
NewExplodeAttributes(int useCurrent)
{
    ExplodeAttributesObject *newObject;
    newObject = PyObject_NEW(ExplodeAttributesObject, &ExplodeAttributesType);
    if(newObject == NULL)
        return NULL;
    if(useCurrent && currentAtts != 0)
        newObject->data = new ExplodeAttributes(*currentAtts);
    else if(defaultAtts != 0)
        newObject->data = new ExplodeAttributes(*defaultAtts);
    else
        newObject->data = new ExplodeAttributes;
    newObject->owns = true;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

static PyObject *
WrapExplodeAttributes(const ExplodeAttributes *attr)
{
    ExplodeAttributesObject *newObject;
    newObject = PyObject_NEW(ExplodeAttributesObject, &ExplodeAttributesType);
    if(newObject == NULL)
        return NULL;
    newObject->data = (ExplodeAttributes *)attr;
    newObject->owns = false;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

///////////////////////////////////////////////////////////////////////////////
//
// Interface that is exposed to the VisIt module.
//
///////////////////////////////////////////////////////////////////////////////

PyObject *
ExplodeAttributes_new(PyObject *self, PyObject *args)
{
    int useCurrent = 0;
    if (!PyArg_ParseTuple(args, "i", &useCurrent))
    {
        if (!PyArg_ParseTuple(args, ""))
            return NULL;
        else
            PyErr_Clear();
    }

    return (PyObject *)NewExplodeAttributes(useCurrent);
}

//
// Plugin method table. These methods are added to the visitmodule's methods.
//
static PyMethodDef ExplodeAttributesMethods[] = {
    {"ExplodeAttributes", ExplodeAttributes_new, METH_VARARGS},
    {NULL,      NULL}        /* Sentinel */
};

static Observer *ExplodeAttributesObserver = 0;

std::string
PyExplodeAttributes_GetLogString()
{
    std::string s("ExplodeAtts = ExplodeAttributes()\n");
    if(currentAtts != 0)
        s += PyExplodeAttributes_ToString(currentAtts, "ExplodeAtts.", true);
    return s;
}

static void
PyExplodeAttributes_CallLogRoutine(Subject *subj, void *data)
{
    typedef void (*logCallback)(const std::string &);
    logCallback cb = (logCallback)data;

    if(cb != 0)
    {
        std::string s("ExplodeAtts = ExplodeAttributes()\n");
        s += PyExplodeAttributes_ToString(currentAtts, "ExplodeAtts.", true);
        cb(s);
    }
}

void
PyExplodeAttributes_StartUp(ExplodeAttributes *subj, void *data)
{
    if(subj == 0)
        return;

    currentAtts = subj;
    PyExplodeAttributes_SetDefaults(subj);

    //
    // Create the observer that will be notified when the attributes change.
    //
    if(ExplodeAttributesObserver == 0)
    {
        ExplodeAttributesObserver = new ObserverToCallback(subj,
            PyExplodeAttributes_CallLogRoutine, (void *)data);
    }

}

void
PyExplodeAttributes_CloseDown()
{
    delete defaultAtts;
    defaultAtts = 0;
    delete ExplodeAttributesObserver;
    ExplodeAttributesObserver = 0;
}

PyMethodDef *
PyExplodeAttributes_GetMethodTable(int *nMethods)
{
    *nMethods = 1;
    return ExplodeAttributesMethods;
}

bool
PyExplodeAttributes_Check(PyObject *obj)
{
    return (obj->ob_type == &ExplodeAttributesType);
}

ExplodeAttributes *
PyExplodeAttributes_FromPyObject(PyObject *obj)
{
    ExplodeAttributesObject *obj2 = (ExplodeAttributesObject *)obj;
    return obj2->data;
}

PyObject *
PyExplodeAttributes_New()
{
    return NewExplodeAttributes(0);
}

PyObject *
PyExplodeAttributes_Wrap(const ExplodeAttributes *attr)
{
    return WrapExplodeAttributes(attr);
}

void
PyExplodeAttributes_SetParent(PyObject *obj, PyObject *parent)
{
    ExplodeAttributesObject *obj2 = (ExplodeAttributesObject *)obj;
    obj2->parent = parent;
}

//****************************************************************************
//  Modifications:
//    Alister Maguire, Wed Jan 10 11:29:50 PST 2018
//    Make defaultAtts point to the passed atts directly.
//
//****************************************************************************
void
PyExplodeAttributes_SetDefaults(const ExplodeAttributes *atts)
{
    defaultAtts = const_cast<ExplodeAttributes*>(atts);
}

